%%%-----------------------------------
%%% @Module  : pt_14
%%% @Author  : xws
%%% @Created : 2016.08.16
%%% @Description: 13物品信息
%%%-----------------------------------
-module(pt_14).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_14_shop.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%% c2s获取商城物品
read(14000, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_shop_goods, Bin),	
	{c2s_get_shop_goods, GoodsType} = ClientData,
    {ok, [GoodsType]};

%% c2s兑换商城物品
read(14001, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_exchange_shop_goods, Bin),	
	{c2s_exchange_shop_goods, GoodsId, Num} = ClientData,
    {ok, [GoodsId, Num]};
	%%{c2s_exchange_shop_goods, GoodsID, GoodsList} = ClientData,
    %%{ok, [GoodsID, [{Gtid, Num} || {_, Gtid, Num} <- GoodsList]]};

%% c2s获取商品购买历史记录
read(14002, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_exchange_his_list, Bin),  
    {c2s_get_exchange_his_list, PlayerId} = ClientData,
    {ok, [PlayerId]};

%% c2s获取收货信息
read(14003, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_receive_info, Bin),  
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};

%% c2s修改收货信息
read(14004, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_change_receive_info, Bin),  
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};

%% 获取验证码
read(14005, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_sms_code, Bin),  
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};

%% 验证手机
read(14006, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_verify_sms_code, Bin),  
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};


read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%
%% s2c获取商城物品
write(14000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_shop_goods, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14000, ServerData)};

%% s2c兑换商城物品
write(14001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_exchange_shop_goods, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14001, ServerData)};

write(14002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_exchange_his_list, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14002, ServerData)};

write(14003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_receive_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14003, ServerData)};

write(14004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_change_receive_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14004, ServerData)};

write(14005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_sms_code, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14005, ServerData)};

write(14006, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_verify_sms_code, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(14006, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.
